<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('导入&创建学习资料')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-material-add">
        <input name="ids" th:value="${ids}" type="hidden"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b" th:with="type=${@dict.getType('material_res_type')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">学习范围：</label>
            <div class="col-sm-8">
                <select name="range" class="form-control m-b" th:with="type=${@dict.getType('material_range')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text" required th:value="${title}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">内容介绍：</label>
            <div class="col-sm-8">
                <textarea name="summary" class="form-control" rows="8" required >[[${title}]]</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标签：</label>
            <div class="col-sm-8">
                <select id="tags" class="form-control select2-multiple" multiple>
                    <option th:each="tag:${tags}" th:value="${tag.name}" th:text="${tag.name}" th:selected="${tag.flag}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">价格：</label>
            <div class="col-sm-8">
                <input name="price" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否广告：</label>
            <div class="col-sm-8">
                <select name="ad" class="form-control m-b" th:with="type=${@dict.getType('common_support')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
        var prefix = ctx + "dict/spider"
        $("#form-material-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
              if ($.validate.form()) {
                 let data = $('#form-material-add').serializeArray()
                 let tags = $.form.selectSelects("tags")
                 data.push({"name": "tags", "value": tags});
                 $.operate.save(prefix + "/material", data);


              }
        }
    </script>
</body>
</html>